package jin.si.service.impl;

import jin.si.dao.ShoppingMapper;
import jin.si.pojo.JsRegion;
import jin.si.pojo.JsUserAddress;
import jin.si.pojo.JsUserCoupon;
import jin.si.pojo.JsUserOrderShop;
import jin.si.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:ShoppingServiceImple
 * Package:jin.si.service.impl
 * Description:
 *
 * @Date:2022/4/8 14:14
 * @Author: XJR
 */
@Service
public class ShoppingServiceImple implements ShoppingService {
    @Autowired
    private ShoppingMapper mapper;

    //加入购物车
    public Boolean addShopOrder(JsUserOrderShop jsUserOrderShop){
        Boolean addShopOrder = mapper.addShopOrder(jsUserOrderShop);
        return addShopOrder;
    };
    //查看是否有默认地址
    public List<JsUserAddress> selectUserDefaultCity(Integer userId,Integer isDefault){
        List<JsUserAddress> jsUserAddress = mapper.selectUserDefaultCity(userId, isDefault);
        return jsUserAddress;
    };
    //查询可选择的地址
    public List<JsRegion> selectJsRegion(Integer parentCode){
        List<JsRegion> jsRegions = mapper.selectJsRegion(parentCode);
        return jsRegions;
    };

    //查询可用以及不可用优惠券
    public List<JsUserCoupon> selectJsCouponYesOrNo(JsUserCoupon jsUserCoupon){
        List<JsUserCoupon> jsUserCoupons = mapper.selectJsCouponYesOrNo(jsUserCoupon);
        return jsUserCoupons;
    };

    //添加用户的收货地址
    public Boolean addUserAddress(JsUserAddress jsUserAddress){
        Boolean addUserAddress = mapper.addUserAddress(jsUserAddress);
        return addUserAddress;
    };

    //查询指定用户的所有地址（默认和非默认）
    public List<JsUserAddress> selectJsAddressAll(Integer userId){
        List<JsUserAddress> jsUserAddresses = mapper.selectJsAddressAll(userId);
        for ( JsUserAddress j :jsUserAddresses){
            if(j.getIsDefault()==2){
                j.setChecked(true);
            }
        }
        return jsUserAddresses;
    };

    //将用户的所有地址改成非默认的
    public Boolean updateUserNoDefault(Integer userId,Integer isDefaultt){
        Boolean updateUserNoDefault = mapper.updateUserNoDefault(userId, isDefaultt);
        return updateUserNoDefault;
    };

    //修改用户的默认地址
    public Boolean updateUserIsDefault(Integer isDefault,Integer addressId){
        Boolean updateUserIsDefault = mapper.updateUserIsDefault(isDefault, addressId);
        return updateUserIsDefault;
    };
}
